/**
 * Cell.java
 * 
 * Copyright (C) 2012 - Thibault BUREL
 * 
 * This file is part of MathDraft.
 *
 * MathDraft is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * MathDraft is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with MathDraft.  If not, see <http://www.gnu.org/licenses/>
 *  
 */
package drk.mathdraft.ihm;

import drk.mathdraft.*;

import java.awt.*;
import java.util.*;

import javax.swing.JPanel;

import org.scilab.forge.jlatexmath.TeXConstants;
import org.scilab.forge.jlatexmath.TeXFormula;
import org.scilab.forge.jlatexmath.TeXIcon;

public class Cell extends JPanel implements Observer {

	private static final long serialVersionUID = 1L;
	
	protected TeXFormula  formula;
	protected TeXIcon    icon;
	protected int        scale;

	public Cell()
	{
		super();
		
		StudiedProposition st = StudiedProposition.getInstance();
		
		this.formula = new TeXFormula (st.getProposition().latexCommands(0));
		st.addObserver(this);
	}
	
    public void paint(Graphics g) {
        super.paint(g);
          	
        this.icon = formula.createTeXIcon(TeXConstants.STYLE_DISPLAY, 30);
            
        icon.paintIcon(this, g, 
        		(this.getWidth() - this.icon.getIconWidth()) / 2,
        		(this.getHeight() - this.icon.getIconHeight()) / 2);
    }
    
	public void update(Observable o, Object arg)
	{
        this.formula = new TeXFormula
        	(StudiedProposition.getInstance()
        			.getProposition().latexCommands(0));

        System.out.println(StudiedProposition.getInstance()
        			.getProposition().latexCommands(0));
        
        this.paintImmediately(this.getBounds());
		//repaint();
	}
}